package com.shootforthestars.components;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Vector2f;

public class CollisionComponent {
	private Shape shape;

	public CollisionComponent() {
		shape = null;
	}

	public CollisionComponent(Rectangle box) {
		this.shape = box;
	}

	public boolean collidesWith(CollisionComponent collidable) {
		return shape.intersects(collidable.getShape());
	}

	public void moveBy(Vector2f v) {
		moveBy(v.x, v.y);
	}

	public void moveBy(float x, float y) {
		moveTo(x + getX(), y + getY());
	}

	public void moveTo(Vector2f v) {
		moveTo(v.x, v.y);
	}

	public void moveTo(float x, float y) {
		setX(x);
		setY(y);
	}

	public Shape getShape() {
		return shape;
	}

	public float getX() {
		return shape.getCenterX();
	}

	public float getY() {
		return shape.getCenterY();
	}

	public float getWidth() {
		return shape.getWidth();
	}

	public float getHeight() {
		return shape.getHeight();
	}

	public void setShape(Shape shape) {
		this.shape = shape;
	}

	public void setCenter(Vector2f v) {
		setCenter(v.x, v.y);
	}

	public void setCenter(float x, float y) {
		setX(x);
		setY(y);
	}

	public void setX(float x) {
		shape.setCenterX(x);
	}

	public void setY(float y) {
		shape.setCenterY(y);
	}

	public void debug(Graphics graphics) {
		graphics.pushTransform();
		graphics.setColor(Color.yellow);
		graphics.draw(shape);
		graphics.popTransform();
	}
}
